package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.UserManagerModer;

import java.util.List;

/**
 * Created by YYY on 2016/4/30.
 */
public class UserManagerListAdapter extends RecyclerView.Adapter<UserManagerListItemVH>{


    private Context context;
    private List<UserManagerModer> userManagerModers;
    private LayoutInflater inflater;
    private View.OnLongClickListener onLongClickListener;
    private View.OnClickListener onClickListener;

    public UserManagerListAdapter(Context context,List<UserManagerModer> userManagerModers)
    {
        this.context=context;
        this.userManagerModers=userManagerModers;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public UserManagerListItemVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=inflater.inflate(R.layout .fragment_user_manager_item_layout,null);
        return new UserManagerListItemVH(itemView);
    }

    @Override
    public void onBindViewHolder(UserManagerListItemVH holder, int position) {

        UserManagerModer userManagerModer=userManagerModers.get(position);
        String userName=TextUtils.isEmpty(userManagerModer.getUserName())?"":userManagerModer.getUserName();
        String userTel=TextUtils.isEmpty(userManagerModer.getTelephone())?"":userManagerModer.getTelephone();
        holder.userNameView.setText("用户名:"+ userName);
        holder.userTelView.setText("电话:"+userTel);

        holder.itemView.setTag(R.id.recyclerview_item_position,position);
        if (null!=onLongClickListener)
        {
            holder.itemView.setOnLongClickListener(onLongClickListener);
        }

        if (null!=onClickListener)
        {
            holder.itemView.setOnClickListener(onClickListener);
        }


    }

    @Override
    public int getItemCount() {

        if (null==userManagerModers)
        {
            return 0;
        }else
        {
            return userManagerModers.size();
        }

    }

    public UserManagerModer getUser(int position)
    {
        return userManagerModers.get(position);
    }

    public List<UserManagerModer> getUserManagerModers() {
        return userManagerModers;
    }

    public void setUserManagerModers(List<UserManagerModer> userManagerModers) {
        this.userManagerModers = userManagerModers;
        notifyDataSetChanged();
    }

    public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
